#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+10;

int T;
int n,m,L,V;
int d[maxn],v[maxn],a[maxn],p[maxn];
int l[maxn],r[maxn];
bool vis[maxn];

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        int s1 = 0;
        for(int i=1;i<=n;i++)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)
            cin>>p[i];
        sort(p+1,p+1+m);
        for(int i=1;i<=n;i++){
            if(d[i] > p[m])
                continue;
            if(a[i] == 0){
                if(v[i] > V){
                    s1++;
                    for(int j=1;j<=m;j++)
                        if(p[j] >= d[i]){
                            l[i] = j;
                            r[i] = m;
                        }
                }
            }
            if(a[i] > 0){
                if(v[i] > V){
                    s1++;
                    for(int j=1;j<=m;j++)
                        if(p[j] >= d[i]){
                            l[i] = j;
                            r[i] = m;
                            break;
                        }
                }else{
                    double dx = (double)(V*V-v[i]*v[i])/(double)(2*a[i]);
                    double nx = d[i]+dx;
                    if(nx <= p[m]){
                        s1++;
                        for(int j=1;j<=m;j++)
                            if(p[j] >= nx){
                                l[i] = j;
                                r[i] = m;
                                break;
                            }
                    }
                }
            }
            if(a[i] < 0){
                if(v[i] <= V)
                    continue;
                double dx = (double)(v[i]*v[i]-V*V)/(double)(2*abs(a[i]));
                double nx = d[i]+dx;
                if(nx >= p[1]){
                    s1++;
                    for(int j=1;j<=m;j++)
                        if(p[j] >= d[i]){
                            l[i] = j;
                            break;
                        }
                    for(int j=1;j<=m;j++)
                        if(p[j] >= nx){
                            r[i] = j-1;
                            break;
                        }
                }
            }
            if(l[i] > r[i])
                l[i] = r[i] = 0;
        }
        cout<<s1<<" "<<s1<<"\n";
    }
    return 0;
}
